import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore(
  'user',
  () => {
    // 数据存储
    const user = ref({})
    const tokenObj = ref({})

    // 存入user
    const setUserInfo = (u) => {
      user.value = u
    }
    // 删除user
    const delUserInfo = () => {
      user.value = {}
    }

    // 存token
    const setToken = (to) => {
      tokenObj.value = to
    }
    const delToken = () => {
      tokenObj.value = {}
    }

    return {
      user,
      tokenObj,

      setUserInfo,
      delUserInfo,
      setToken,
      delToken
    }
  },
  {
    persist: true
  }
)
